package jjn.round2;

/**
 * @author Jiang Jining
 * @since 2023-05-04 23:23
 */
public class Offer42_MaxSubArray {
    public int maxSubArray(int[] nums) {
        int max = nums[0];
        int former = 0; // dp[i -1]
        int current; // dp[i]
        for (int num : nums) {
            current = num;
            if (former > 0) {
                current += former;
            }
            if (current > max) {
                max = current;
            }
            former = current;
        }
        return max;
    }
}
